import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
//import Room from "../views/Room.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home
  },

  {
    path: "/room",
    name: "Room",
    props: true,
    beforeEnter: (to,from,next) => {
      //console.log(to.params.name);
      if (to.params.name) {
        next()  
      } else {
        next({name:'Home'})
      }
      
      // console.log(from);
      // console.log(next);
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "room" */ "../views/Room.vue")
  }
];

const router = new VueRouter({
  mode:'history',
  routes
});

export default router;
